package com.ruoyi.web.controller.manager;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MilestoneTask;
import com.ruoyi.system.service.IMilestoneTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 里程碑与任务中间表Controller
 * 
 * @author ruoyi
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/system/mileTask")
public class MilestoneTaskController extends BaseController
{
    @Autowired
    private IMilestoneTaskService milestoneTaskService;

    /**
     * 查询里程碑与任务中间表列表
     */
    @PreAuthorize("@ss.hasPermi('system:mileTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(MilestoneTask milestoneTask)
    {
        startPage();
        List<MilestoneTask> list = milestoneTaskService.selectMilestoneTaskList(milestoneTask);
        return getDataTable(list);
    }

    /**
     * 导出里程碑与任务中间表列表
     */
    @PreAuthorize("@ss.hasPermi('system:mileTask:export')")
    @Log(title = "里程碑与任务中间表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MilestoneTask milestoneTask)
    {
        List<MilestoneTask> list = milestoneTaskService.selectMilestoneTaskList(milestoneTask);
        ExcelUtil<MilestoneTask> util = new ExcelUtil<MilestoneTask>(MilestoneTask.class);
        util.exportExcel(response, list, "里程碑与任务中间表数据");
    }

    /**
     * 获取里程碑与任务中间表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:mileTask:query')")
    @GetMapping(value = "/{milestoneId}")
    public AjaxResult getInfo(@PathVariable("milestoneId") Long milestoneId)
    {
        return success(milestoneTaskService.selectMilestoneTaskByMilestoneId(milestoneId));
    }

    /**
     * 新增里程碑与任务中间表
     */
    @PreAuthorize("@ss.hasPermi('system:mileTask:add')")
    @Log(title = "里程碑与任务中间表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MilestoneTask milestoneTask)
    {
        return toAjax(milestoneTaskService.insertMilestoneTask(milestoneTask));
    }

    /**
     * 修改里程碑与任务中间表
     */
    @PreAuthorize("@ss.hasPermi('system:mileTask:edit')")
    @Log(title = "里程碑与任务中间表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MilestoneTask milestoneTask)
    {
        return toAjax(milestoneTaskService.updateMilestoneTask(milestoneTask));
    }

    /**
     * 删除里程碑与任务中间表
     */
    @PreAuthorize("@ss.hasPermi('system:mileTask:remove')")
    @Log(title = "里程碑与任务中间表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{milestoneIds}")
    public AjaxResult remove(@PathVariable Long[] milestoneIds)
    {
        return toAjax(milestoneTaskService.deleteMilestoneTaskByMilestoneIds(milestoneIds));
    }
}
